package grape.house.service.estatelicence.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.common.service.common.IBaseService;
import grape.common.service.trans.ITransService;
import grape.house.service.estatelicence.po.EstateLicence;

import java.util.List;

/**
 * <p>
 * 楼盘许可证表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-09-17
 */
public interface IEstateLicenceService extends IBaseService<EstateLicence> , ITransService<String,String> {

    public static final String trans_estate_licence_name = "trans_estate_licence_name";
    public static final String trans_estate_licence_code = "trans_estate_licence_code";

    /**
     * 根据编码查询
     * @param code
     * @return
     */
    default EstateLicence getByCode(String code) {
        assertParamNotEmpty(code,"code 不能为空");
        EstateLicence estate_licence = new EstateLicence();
        estate_licence.setCode(code);
        return getOne(estate_licence);
    }
    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");
        EstateLicence comp = new EstateLicence();
        comp.setCode(code);
        int r = count(Wrappers.query(comp));
        return r > 0;
    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_estate_licence_code, trans_estate_licence_name);
    }

    @Override
    default String trans(String type, String key){
        EstateLicence po = getById(key);
        if (po != null) {
            if (isEqual(type,trans_estate_licence_name)) {
                return po.getName();
            }else if (isEqual(type,trans_estate_licence_code)) {
                return po.getCode();
            }
        }
        return null;
    }

    /**
     * 根据楼盘id查询
     * @param estateId 楼盘id
     * @return
     */
    default List<EstateLicence> getByEstateId(String estateId) {
        assertParamNotEmpty(estateId,"estateId不能为空");
        EstateLicence estateLicence = new EstateLicence();
        estateLicence.setEstateId(estateId);
        return list(estateLicence);
    }


    /**
     * 根据楼盘id 和 类型id查询
     * @param estateId 楼盘id
     * @param permitTypeDictId 类型字典id
     * @return
     */
    default List<EstateLicence> getByEstateIdAndPermitTypeDictId(String estateId,String permitTypeDictId) {
        assertParamNotEmpty(estateId,"estateId不能为空");
        assertParamNotEmpty(permitTypeDictId,"permitTypeDictId不能为空");
        EstateLicence estateLicence = new EstateLicence();
        estateLicence.setEstateId(estateId);
        estateLicence.setPermitTypeDictId(permitTypeDictId);
        return list(estateLicence);
    }
}
